package com.fosu.dao;

import com.fosu.domain.Campus;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zqa
 * @version 1.0
 */
@Mapper
@Repository
public interface CampusDao {
    /**查找所有校区
     * @return List<Campus> 校区对象集合
     * @throws Exception
     */
    @Select("select * from campus")
    @Results(id="campusMap",value = {
            @Result(id = true, property = "campusId", column = "campus_id"),
            @Result(property = "campusName", column = "campus_name")
    })
    List<Campus> findAll() throws Exception;


    /**根据商品id获得商品校区
     * @param productId 商品id
     * @return List<Campus> 校区对象集合
     * @throws Exception*/
    @Select("select c.campus_id,campus_name " +
            "from campus c,product_campus pc" +
            " where pc.product_id=#{productId}" +
            " and pc.campus_id=c.campus_id")
    @ResultMap(value = "campusMap")
    List<Campus> findCampusById(int productId) throws Exception;

    /**根据用户id获得商品校区
     * @param userId 用户id
     * @return Campus 校区对象
     * @throws Exception*/
    @Select("select c.campus_id,campus_name " +
            "from campus c,user_campus uc" +
            " where uc.user_id=#{userId}" +
            " and uc.campus_id=c.campus_id")
    @ResultMap(value = "campusMap")
    Campus findCampusByUserId(int userId) throws Exception;

}


